package world.hezi.callback;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * @author wangzijian
 * @since 2023/11/9 15:54
 */
public class LongPicturesCallBack implements Callback {

    private CountDownLatch countDownLatch;
    private String uuid;

    public LongPicturesCallBack(CountDownLatch countDownLatch, String uuid) {
        this.countDownLatch = countDownLatch;
        this.uuid = uuid;
    }

    @Override
    public void onFailure(@NotNull Call call, @NotNull IOException e) {
        countDownLatch.countDown();
    }

    @Override
    public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
        try(FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\65134\\Desktop\\long\\test\\"+uuid)) {
            fileOutputStream.write(response.body().bytes());
            fileOutputStream.close();
            countDownLatch.countDown();
        }catch (Exception e){

        }finally {
            countDownLatch.countDown();
        }

    }
}
